import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;


public class ConvertClass {

	private static BufferedReader in;
	private static PrintWriter classOut;
	public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException {
		in = new BufferedReader(new FileReader("class.txt"));
		classOut = new PrintWriter(new FileWriter("final_class.txt"));
		Connection conn = ConnectionManager.openConnection();
		Statement st = conn.createStatement();
		ResultSet rs = st.executeQuery("select * from package");
		HashMap<String, Integer> pkmap = new HashMap<String, Integer>();
		while (rs.next()) {
			pkmap.put(rs.getString("pname"), rs.getInt("pid"));
		}
		String line = in.readLine();
		while (line != null) {
			String[] lineSegs = line.split(" ");
			lineSegs[2] = (pkmap.get(lineSegs[2])).toString();
			classOut.println("insert into `class` (`cname`, `ctype`, `package_id`,`src_name`, `parent_id`) values ('" +
			lineSegs[0] + "', " + lineSegs[1] + ", " + lineSegs[2] + ", '" + lineSegs[3] + "', " + lineSegs[4] + ");");
			line = in.readLine();
		}
		rs.close();
		st.close();
		conn.close();
		in.close();
		classOut.close();
	}
}